home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_htmllib.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2005-10-18  |  2.9 KB  |  69 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import formatter
  5. import htmllib
  6. import unittest
  7. from test import test_support
  8.  
  9. class AnchorCollector(htmllib.HTMLParser):
  10.     
  11.     def __init__(self, *args, **kw):
  12.         self._AnchorCollector__anchors = []
  13.         htmllib.HTMLParser.__init__(self, *args, **kw)
  14.  
  15.     
  16.     def get_anchor_info(self):
  17.         return self._AnchorCollector__anchors
  18.  
  19.     
  20.     def anchor_bgn(self, *args):
  21.         self._AnchorCollector__anchors.append(args)
  22.  
  23.  
  24.  
  25. class DeclCollector(htmllib.HTMLParser):
  26.     
  27.     def __init__(self, *args, **kw):
  28.         self._DeclCollector__decls = []
  29.         htmllib.HTMLParser.__init__(self, *args, **kw)
  30.  
  31.     
  32.     def get_decl_info(self):
  33.         return self._DeclCollector__decls
  34.  
  35.     
  36.     def unknown_decl(self, data):
  37.         self._DeclCollector__decls.append(data)
  38.  
  39.  
  40.  
  41. class HTMLParserTestCase(unittest.TestCase):
  42.     
  43.     def test_anchor_collection(self):
  44.         parser = AnchorCollector(formatter.NullFormatter(), verbose = 1)
  45.         parser.feed("<a href='http://foo.org/' name='splat'> </a>\n            <a href='http://www.python.org/'> </a>\n            <a name='frob'> </a>\n            ")
  46.         parser.close()
  47.         self.assertEquals(parser.get_anchor_info(), [
  48.             ('http://foo.org/', 'splat', ''),
  49.             ('http://www.python.org/', '', ''),
  50.             ('', 'frob', '')])
  51.  
  52.     
  53.     def test_decl_collection(self):
  54.         parser = DeclCollector(formatter.NullFormatter(), verbose = 1)
  55.         parser.feed('<html>\n            <body>\n            hallo\n            <![if !supportEmptyParas]> <![endif]>\n            </body>\n            </html>\n            ')
  56.         parser.close()
  57.         self.assertEquals(parser.get_decl_info(), [
  58.             'if !supportEmptyParas',
  59.             'endif'])
  60.  
  61.  
  62.  
  63. def test_main():
  64.     test_support.run_unittest(HTMLParserTestCase)
  65.  
  66. if __name__ == '__main__':
  67.     test_main()
  68.  
  69.